package awesome.cpu.structure;

import awesome.cpu.utils.Mode;

public class PCRegister extends SequentialComponent{
	
	private final static PCRegister mInstance = new PCRegister();
	
	private static boolean outputDebug = false;
	
	public static PCRegister getInstance(){
		return mInstance;
	}
	
	private PCRegister(){}
	
	public final static int KEY_PCREG_IN = 1;
	private int mPCRegIn;
	
	public final static int KEY_PCREG_OUT = 2;
	private int mPCRegOut;
	
	public final static int KEY_PCREG_WRITE = 3;
	private int mPCRegWrite;

	@Override
	void onClockTick() {	
		if (mPCRegWrite == 1)
			mPCRegOut = mPCRegIn;
		if (outputDebug && Mode.getDebugLevel() >= Mode.DEBUG_LEVEL_PRINT_ALL)
			System.out.println("PCRegister out = " + mPCRegOut);
	}

	@Override
	int getData(int keyInterface) {
	
		if (keyInterface == KEY_PCREG_OUT)
			return mPCRegOut;
		
		return 0;
	}

	@Override
	boolean setData(int keyInterface, int data) {
		
		if (keyInterface == KEY_PCREG_IN){
			mPCRegIn = data;
			return true;
		}else if (keyInterface == KEY_PCREG_WRITE){
			mPCRegWrite = data;
			return true;
		}
		
		
		return false;
	}
	

}
